package com.hsjk.szwj.module.system.controller.app.poster;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.framework.security.core.annotations.PreAuthenticated;
import com.hsjk.szwj.module.system.controller.app.poster.vo.AppPosterDetailRespVO;
import com.hsjk.szwj.module.system.controller.app.poster.vo.AppPosterPageReqVO;
import com.hsjk.szwj.module.system.controller.app.poster.vo.AppPosterPageRespVO;
import com.hsjk.szwj.module.system.service.poster.IPosterConfig;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/12/11 16:12
 **/
@Tag(name = "前端 - 海报配置相关接口")
@RestController
@RequestMapping("/system/poster")
@Validated
public class AppPosterController {
    @Resource
    private IPosterConfig posterConfig;

    @PutMapping("/set-poster")
    @Operation(summary = "设置选中海报")
    @PreAuthenticated
    public CommonResult<Boolean> setPoster(@RequestParam Long id) {
        posterConfig.setPoster(id);
        return success(true);
    }

    @PostMapping("/page-poster")
    @Operation(summary = "分页获取海报列表")
    @PreAuthenticated
    public CommonResult<PageResult<AppPosterPageRespVO>> getAdminPosterPage(
            @RequestBody @Valid AppPosterPageReqVO reqVO) {
        return success(posterConfig.getAppPosterPage(reqVO));
    }

    @GetMapping("/get-set-poster")
    @Operation(summary = "获取选中的海报")
    @PreAuthenticated
    public CommonResult<AppPosterDetailRespVO> getAppSetPoster() {
        return success(posterConfig.getAppSetPoster());
    }
}
